//
//  P1219chess.cpp
//  suanfa
//
//  Created by 刘锦程 on 2023/9/6.
//

#include <stdio.h>
#include <iostream>
#include<cstdio>
using namespace std;
int book[14][14],n=0,chessN=1,ans;
bool chessOK(int x,int y){
    for(int i=1;i<=n;i++){
        if(book[i][y]==1) return 0;
    }
    for(int i=1-n;i<=n-1;i++){
        if(x+i>=1&&y+i>=1&&x+i<=n&&y+i<=n)
           if(book[x+i][y+i]){
            return 0;
        }
    }
    for(int i=1-n;i<=n-1;i++){
        if(x+i>=1&&y-i>=1&&x+i<=n&&y-i<=n)
            if(book[x+i][y-i]){
            return 0;
        }
    }
    return 1;
}
void print(){
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(book[i][j]) printf("%d ",j);
        }
    }
    printf("\n");
}
void dfs(int x,int y){
    chessN++;
    if(chessN==n+1){
        ans++;
        if(ans<=3)
        print();
        return;
    }else{
        book[x][y]=1;
        for(int z=1;z<=n;z++){
            
            if(chessOK(chessN, z)){
                book[chessN][z]=1;
                dfs(chessN,z);
                chessN--;
                book[chessN][z]=0;
            }
        }
        return;
    }
}
void P1219ans(){
    cin>>n;
    for(int k=1;k<=n;k++){
    dfs(1,k);
    chessN--;
    book[1][k]=0;
    }
   printf("%d\n",ans);
    
    
    
}
